package com.cskaoyan.shopping.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.constant.ShoppingRetCode;
import com.cskaoyan.shopping.dto.TestProductDetailDto;
import com.cskaoyan.shopping.dto.TestProductDetailRequest;
import com.cskaoyan.shopping.dto.TestProductDetailResponse;
import com.cskaoyan.shopping.service.ITestProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther cskaoyan
 * @date 2022/5/18:11:34
 */
@RestController
public class TestProductDetailController {

    @Autowired
    ITestProductService  testProductService;

    @GetMapping("/shopping/test")
    public ResponseData getProductDetail(Long productId) {

        TestProductDetailRequest request = new TestProductDetailRequest();
        request.setProductId(productId);


        // 根据业务逻辑处理请求
        TestProductDetailResponse productDetail = testProductService.getProductDetail(request);

        if (ShoppingRetCode.SUCCESS.getCode().equals(productDetail.getCode())) {
            // 业务方法调用成功
            TestProductDetailDto result = productDetail.getTestProductDetailDto();
            return new ResponseUtil().setData(result);
        }

        // 业务方法执行失败
        return new ResponseUtil().setErrorMsg(productDetail.getMsg());
    }
}
